package com.ddtech.business.check.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ddtech.business.check.entity.CheckUserAnswer;
import com.ddtech.business.check.entity.CheckUserQuestion;
import com.ddtech.business.check.mapper.CheckUserAnswerMapper;
import com.ddtech.business.check.mapper.CheckUserQuestionMapper;
import com.ddtech.business.check.query.CheckUserAnswerQuery;
import com.ddtech.business.check.service.CheckService;
import com.ddtech.business.check.service.CheckUserAnswerService;
import com.ddtech.business.check.vo.res.QueAndOpt;
import com.ddtech.utils.PageUtil;
import com.ddtech.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 考核用户答案 服务实现类
 * </p>
 *
 * @author bin_pu
 * @since 2023-02-06
 */
@Service
public class CheckUserAnswerServiceImpl extends ServiceImpl<CheckUserAnswerMapper, CheckUserAnswer> implements CheckUserAnswerService {
    @Resource
    private CheckUserQuestionMapper checkUserQuestionMapper;
    @Autowired
    private CheckService checkService;

    @Override
    public Object getErrorPageList(CheckUserAnswerQuery checkUserAnswerQuery) {
        IPage<CheckUserQuestion> errorPageList = checkUserQuestionMapper.getErrorPageList(checkUserAnswerQuery.populatePage(), checkUserAnswerQuery.getQuestionName(), SecurityUtils.getUserId());
        List<CheckUserQuestion> records = errorPageList.getRecords();
        List<QueAndOpt> typeQuestion = checkService.getTypeQuestion(SecurityUtils.getUserId(), records);
        return PageUtil.toPage(typeQuestion, errorPageList.getTotal());
    }
}
